package com.ht.dao;

import com.ht.bean.*;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface PermissionDao {
    //系统权限管理数据————————————————————————————————————————————————————————————————————————————————
    //查询角色权限表
    @Select({"<script>",
            "select * from characters ",
            "<where>",
            "<if test=\" characters.characterId!= null and characters.characterId!= ''\">",
            "and characterId=#{characters.characterId}",
            "</if>",
            "<if test=\" characters.characterName!= null and characters.characterName!= ''\">",
            "and characterName like concat('%',#{characters.characterName},'%')",
            "</if>",
            "</where>",
            "<if test=\" lime != null and lime!=''\">",
            "limit #{pid},#{lime}",
            "</if>",
            "</script>"})
    List<Characters> litcha(@Param("pid") Integer pid, @Param("lime") Integer lime , @Param("characters") Characters characters);

    //查询权限角色表的数据的数量
    @Select({"<script>",
            "select count(*) from characters ",
            "<where>",
            "<if test=\" characters.characterId!= null and characters.characterId!= ''\">",
            "and characterId=#{characters.characterId}",
            "</if>",
            "<if test=\" characters.characterName!= null and characters.characterName!= ''\">",
            "and characterName like concat('%',#{characters.characterName},'%')",
            "</if>",
            "</where>",
            "</script>"})
    int cuntcha(@Param("characters") Characters characters);

    //新增前查询需要绑定的岗位表
    @Select("select * from Post")
    List<Post> lidpost();

    //新增权限角色
    @Insert({"<script>",
            "insert into characters values " +
            "(null,#{characters.characterName},#{characters.postId}) "+
            "</script>"})
    boolean  addchare(@Param("characters") Characters characters);

    //删除权限角色
    @Delete("delete from characters where characterId = #{characterId}")
    boolean delchare(@Param("characterId") Integer characterId);

    //修改权限角色表前的查询
    @Select("select * from characters where characterId = #{characterId}")
    Characters litupre(@Param("characterId") Integer characterId);
    //修改权限角色
    @Update("update characters set characterName = #{characters.characterName} where characterId =#{characters.characterId}")
    boolean upchare(@Param("characters") Characters characters);
    //查询角色现拥有的系统权限
    @Select("<script>" +
            "select le.moduleId from characters er,charmodule le"+
            "<where>"+
            "and er.characterId = le.characterId and er.characterId = #{characterId}"+
            "</where>"+
            "</script>")
    List<Integer> litquan(@Param("characterId") Integer characterId);
    //查询角色现拥有的系统权限的数量
    @Select("<script>" +
            "select count(*) from characters er,charmodule le"+
            "<where>"+
            "and er.characterId = le.characterId and er.characterId = #{characterId}"+
            "</where>"+
            "</script>")
    int litquann(@Param("characterId") Integer characterId);
    //删除角色的系统权限
    @Delete("delete from charmodule where characterId = #{characterId}")
    boolean delmodeid(Integer characterId);
    //新增角色的系统权限
    @Insert({"<script>",
            "insert into charmodule values" +
            "<foreach collection =\"charmodule\" item=\"item\" separator =\",\">" +
            "(null,#{item.moduleId},#{item.characterId}) "+
            "</foreach >"+
            "</script>"})
    boolean indmodel(@Param("charmodule") List<Charmodule> charmodule);

    //查询系统权限管理表
    @Select("Select * from module")
    List<Module> modlid();
    //查询系统权限表数量
    @Select("select count(*) from module")
    int modactu();


    //查询拥有该角色的员工的id，通过角色id查询
    @Select("select ch.empId from charemp ch where characterId = #{characterId}")
    List<Integer> litchempid(Integer characterId);

    //查询部门表
    @Select("select d.depid,d.depName,d.parentId from dep d")
    List<Dep> litdepduijian();

    //查询员工表
    @Select("select e.empId,e.empName,e.depId from emp e")
    List<Emp> litempduijian();

    //删除用户角色表的数据
    @Delete("delete from charemp where characterId = #{characterId}")
    boolean delcemp(@Param("characterId") Integer characterId);

    //新增用户角色表的数据
    @Insert({"<script>",
            "insert into charemp values" +
                    "<foreach collection =\"charemp\" item=\"item\" separator =\",\">" +
                    "(null,#{item.empId},#{item.characterId}) "+
                    "</foreach >"+
                    "</script>"})
    boolean inschaemp(@Param("charemp") List<Charemp> charemp);
    //    "insert into charemp values(null,#{charemp.empId},#{charemp.characterId}) "

}
